package com.wwwarehouse.usercenter.fragment.register;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wei.android.lib.fingerprintidentify.FingerprintIdentify;
import com.wei.android.lib.fingerprintidentify.base.BaseFingerprint;
import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.bean.upload.FileUploadBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.popupwindow.EasyPopupWindow;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.common.tools.DeviceUtils;
import com.wwwarehouse.common.tools.DialogTools;
import com.wwwarehouse.common.tools.FileUtils;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.activity.RegisterCardActivity;
import com.wwwarehouse.usercenter.activity.SystemServiceActivity;
import com.wwwarehouse.usercenter.bean.response.LoginResponseBean;
import com.wwwarehouse.usercenter.common.UserCenterCommon;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;
import de.greenrobot.event.EventBus;

import static com.wwwarehouse.usercenter.constant.UserCenterConstant.sp_Finger;

/**
 * 拼卡界面
 * Created by xiaoke.ni on 2017/8/10.
 */
public class RegisterCardFragment extends RegisterCardBaseFragment implements View.OnClickListener {

    private View mRootView;

    private RelativeLayout mRlRegisterCardServiceContract;//入网协议
    private ImageView      mIvRegisterCardServiceContract;
    private TextView       mTvRegisterCardServiceContract;
    private RelativeLayout mRlRegisterCardInviteCode;//邀请码
    private ImageView      mIvRegisterCardInviteCode;
    private TextView       mTvRegisterCardInviteCode;
    private RelativeLayout mRlRealNameAuth;//实名认证
    private ImageView      mIvRealNameAuth;
    private TextView       mTvRealNameAuth;
    private RelativeLayout mRlUserNamePassword;//用户名和密码
    private ImageView      mIvUserNamePassword;
    private TextView       mTvUserNamePassword;
    private RelativeLayout mRlShootingHead;//拍摄头像
    private ImageView      mIvShootingHead;
    private TextView       mTvShootingHead;
    private RelativeLayout mRlBinding;//绑定
    private ImageView      mIvBinding;
    private TextView       mTvBinding;
    private RelativeLayout mRlFingerprintUnlockSettings;//指纹解锁设置
    private ImageView      mIvFingerprintUnlockSettings;
    private TextView       mTvFingerprintUnlockSettings;
    private RelativeLayout mRlInputData;//录入员工资料
    private ImageView      mIvInputData;
    private TextView       mTvInputData;


    //用于判断哪一项完成
    //    private boolean           isShootingHead;
    private ElasticScrollView mElasticScrollView;
    private Button            mBtSubmit;
    private boolean           isSubVisible;
    private EasyPopupWindow   mEasyPopupWindow;
    private View              PopItemView;
    private String mHeadPhoto = "headphoto";
    private FileUtils           mFileUtils;
    private List<String>        mHeadList;
    private FingerprintIdentify mFingerprintIdentify;
    private ImageView           mIvHead;
    private TextView            mTvUserName;
    private TextView            mTvBindPhone;
    private TextView            mTvBindEmail;
    private TextView            mTvInputDatas;
    private int step = 8;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_register_card, container, false);

        return mRootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        EventBus.getDefault().register(this);

        initView();
        initData();
        initEvent();
    }

    private void initData() {

        //        isSystemServiceActivity = UserCenterCommon.getInstance().isSystemServiceActivity();
        //        isRCInviteCodeFragment = UserCenterCommon.getInstance().isRCInviteCodeFragment();
        //        isRCRealNameAuthStep2Fragment = UserCenterCommon.getInstance().isRCRealNameAuthStep2Fragment();
        //        isShootHead = UserCenterCommon.getInstance().isShootHead();
        //        isRCUserNamePasswordFragment = UserCenterCommon.getInstance().isRCUserNamePasswordFragment();
        //        isRCBindingFragment = UserCenterCommon.getInstance().isRCBindingFragment();
        //        isFingerUnlockSettingsFragment = UserCenterCommon.getInstance().isFingerUnlockSettingsFragment();
        //        isEnterEmployeeDataFragment = UserCenterCommon.getInstance().isEnterEmployeeDataFragment();
        //        changeView();
    }

    private void initView() {
        mIvHead = findView(mRootView, R.id.iv_head);
        mTvUserName = findView(mRootView, R.id.tv_user_name);
        mTvBindPhone = findView(mRootView, R.id.tv_binding_phont);
        mTvBindEmail = findView(mRootView, R.id.tv_binding_email);
        mTvInputDatas = findView(mRootView, R.id.tv_input_datas);

        mFileUtils = new FileUtils();
        mElasticScrollView = findView(mRootView, R.id.regist_elastic_scroll);
        mBtSubmit = findView(mRootView, R.id.bt_submit);
        mRlRegisterCardServiceContract = findView(mRootView, R.id.rl_register_card_service_contract);
        mIvRegisterCardServiceContract = findView(mRootView, R.id.iv_register_card_service_contract);
        mTvRegisterCardServiceContract = findView(mRootView, R.id.tv_register_card_service_contract);
        mRlRegisterCardInviteCode = findView(mRootView, R.id.rl_register_card_invite_code);
        mIvRegisterCardInviteCode = findView(mRootView, R.id.iv_register_card_invite_code);
        mTvRegisterCardInviteCode = findView(mRootView, R.id.tv_register_card_invite_code);
        mRlRealNameAuth = findView(mRootView, R.id.rl_real_name_auth);
        mIvRealNameAuth = findView(mRootView, R.id.iv_real_name_auth);
        mTvRealNameAuth = findView(mRootView, R.id.tv_real_name_auth);
        mRlUserNamePassword = findView(mRootView, R.id.rl_user_name_password);
        mIvUserNamePassword = findView(mRootView, R.id.iv_user_name_password);
        mTvUserNamePassword = findView(mRootView, R.id.tv_user_name_password);
        mRlShootingHead = findView(mRootView, R.id.rl_shooting_head);
        mIvShootingHead = findView(mRootView, R.id.iv_shooting_head);
        mTvShootingHead = findView(mRootView, R.id.tv_shooting_head);
        mRlBinding = findView(mRootView, R.id.rl_binding);
        mIvBinding = findView(mRootView, R.id.iv_binding);
        mTvBinding = findView(mRootView, R.id.tv_binding);
        mRlFingerprintUnlockSettings = findView(mRootView, R.id.rl_fingerprint_unlock_settings);
        mIvFingerprintUnlockSettings = findView(mRootView, R.id.iv_fingerprint_unlock_settings);
        mTvFingerprintUnlockSettings = findView(mRootView, R.id.tv_fingerprint_unlock_settings);
        mRlInputData = findView(mRootView, R.id.rl_input_data);
        mIvInputData = findView(mRootView, R.id.iv_input_data);
        mTvInputData = findView(mRootView, R.id.tv_input_data);

    }

    private void initEvent() {
        mElasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {
                if (isSystemServiceActivity && isRCInviteCodeFragment && isRCRealNameAuthStep2Fragment && isShootHead && isRCUserNamePasswordFragment && isRCBindingFragment) {
                    ((RegisterCardActivity) mActivity).setBnt1ReadyColor();
                } else {
                    ((RegisterCardActivity) mActivity).setBnt1UnReadyColor();
                }
                ((RegisterCardActivity) mActivity).hideShowTitle(true);

            }

            @Override
            public void onUpPull() {
            }
        });

        mRlRegisterCardServiceContract.setOnClickListener(this);
        mRlRegisterCardInviteCode.setOnClickListener(this);
        mRlRealNameAuth.setOnClickListener(this);
        mRlShootingHead.setOnClickListener(this);
        mRlUserNamePassword.setOnClickListener(this);
        mRlBinding.setOnClickListener(this);
        mRlFingerprintUnlockSettings.setOnClickListener(this);
        mRlInputData.setOnClickListener(this);
    }

    private boolean isSystemServiceActivity;
    private boolean isRCInviteCodeFragment;
    private boolean isRCRealNameAuthStep2Fragment;
    private boolean isShootHead;
    private boolean isRCUserNamePasswordFragment;
    private boolean isRCBindingFragment;
    private boolean isFingerUnlockSettingsFragment;
    private boolean isEnterEmployeeDataFragment;

    @Override
    public void onClick(View v) {
        if (v == mRlRegisterCardServiceContract) {
            if (!isSystemServiceActivity) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                Intent intent = new Intent(mActivity, SystemServiceActivity.class);
                startActivity(intent);
            } else {
                toast(getResources().getString(R.string.sure_enter_web));
            }
        } else if (v == mRlRegisterCardInviteCode) {
            if (!isRCInviteCodeFragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new RCInviteCodeFragment());
            } else {
                toast(getResources().getString(R.string.sure_invite_code));
            }
        } else if (v == mRlRealNameAuth) {
            if (isSystemServiceActivity && isRCInviteCodeFragment && !isRCRealNameAuthStep2Fragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new RCRealNameAuthStep1Fragment());
            } else if (isRCRealNameAuthStep2Fragment) {
                toast(getResources().getString(R.string.sure_real_name));
            } else if (!isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web_code));
            } else if (!isSystemServiceActivity && isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web));
            } else if (isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.code));
            }
        } else if (v == mRlShootingHead) {
            if (isSystemServiceActivity && isRCInviteCodeFragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new RCShootingHeadFragment());
            } else if (!isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web_code));
            } else if (!isSystemServiceActivity && isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web));
            } else if (isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.code));
            }
        } else if (v == mRlUserNamePassword) {
            if (isSystemServiceActivity && isRCInviteCodeFragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new RCUserNamePasswordFragment());
            } else if (!isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web_code));
            } else if (!isSystemServiceActivity && isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web));
            } else if (isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.code));
            }
        } else if (v == mRlBinding) {
            if (isSystemServiceActivity && isRCInviteCodeFragment && !isRCBindingFragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new RCBindingFragment());
            } else if (isRCBindingFragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new ImproveInformationFragment());
            } else if (!isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web_code));
            } else if (!isSystemServiceActivity && isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web));
            } else if (isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.code));
            }
        } else if (v == mRlFingerprintUnlockSettings) {
            if (isSystemServiceActivity && isRCInviteCodeFragment) {
                mFingerprintIdentify = new FingerprintIdentify(BaseApplication.getApplicationInstance(), new BaseFingerprint.FingerprintIdentifyExceptionListener() {
                    @Override
                    public void onCatchException(Throwable exception) {
                        LogUtils.showLog(exception.getLocalizedMessage());
                    }
                });
                if (!mFingerprintIdentify.isHardwareEnable()) {
                    //手机硬件不支持指纹识别
                    toast(mActivity.getResources().getString(R.string.no_sys_finger));
                    return;
                }
                if (!mFingerprintIdentify.isRegisteredFingerprint()) {
                    //手机没有录入指纹
                    DialogTools.getInstance().showCustomDialogPromptNoTitle(mActivity, mActivity.getResources().getString(R.string.no_finger), false, new DialogTools.ConfirmListener() {
                        @Override
                        public void setConfirmListener(Dialog dialog, View view, String s) {
                            //打开设置系统界面
                            mActivity.startActivity(new Intent(Settings.ACTION_SETTINGS));
                            dialog.dismiss();
                        }
                    }, mActivity.getString(R.string.go_finger), mActivity.getString(R.string.not_go_finger));
                    return;
                }
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new FingerUnlockSettingsFragment());
            } else if (!isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web_code));
            } else if (!isSystemServiceActivity && isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web));
            } else if (isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.code));
            }
        } else if (v == mRlInputData) {
            if (isSystemServiceActivity && isRCInviteCodeFragment) {
                ((RegisterCardActivity) mActivity).restoreTitle();
                pushFragment(new EnterEmployeeDataFragment());
            } else if (!isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web_code));
            } else if (!isSystemServiceActivity && isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.web));
            } else if (isSystemServiceActivity && !isRCInviteCodeFragment) {
                toast(getResources().getString(R.string.code));
            }
        }
    }

    private void getHeadIsOk() {
        //判断头像是否上传完成
        if (!TextUtils.isEmpty(UserCenterCommon.getInstance().getFace())) {
            Submit();
        } else {
            //继续上传图片
            List<String> listFead = new ArrayList<>();
            listFead.add(UserCenterCommon.getInstance().getAbsolutePath());
            uploadPhoto(listFead);
        }
    }

    public void Submit() {

        Map saveUseMgsMap = new HashMap<>();
        saveUseMgsMap.put("birthPlace", UserCenterCommon.getInstance().getBirthPlace());
        saveUseMgsMap.put("birthday", UserCenterCommon.getInstance().getBirthday());
        saveUseMgsMap.put("deviceInfo", DeviceUtils.getDeviceInfo(mActivity));
        saveUseMgsMap.put("deviceMac", DeviceUtils.getDeviceMac());
        saveUseMgsMap.put("deviceToken", JPushInterface.getRegistrationID(BaseApplication.getApplicationInstance()));
        saveUseMgsMap.put("deviceType", "a");
        saveUseMgsMap.put("disabilitySituation", UserCenterCommon.getInstance().getDisabilitySituation());
        saveUseMgsMap.put("email", UserCenterCommon.getInstance().getEmail());
        saveUseMgsMap.put("expirationDate", UserCenterCommon.getInstance().getExpirationDate());
        saveUseMgsMap.put("eyesight", UserCenterCommon.getInstance().getEyesight());
        saveUseMgsMap.put("face", UserCenterCommon.getInstance().getFace());//
        saveUseMgsMap.put("height", UserCenterCommon.getInstance().getHeight());
        saveUseMgsMap.put("idBack", UserCenterCommon.getInstance().getIdBack());
        saveUseMgsMap.put("idCard", UserCenterCommon.getInstance().getIdCard());
        saveUseMgsMap.put("idFront", UserCenterCommon.getInstance().getIdFront());
        saveUseMgsMap.put("idHeader", UserCenterCommon.getInstance().getIdHeader());
        saveUseMgsMap.put("inviteCode", UserCenterCommon.getInstance().getInviteCode());
        saveUseMgsMap.put("mobile", UserCenterCommon.getInstance().getMobile());
        saveUseMgsMap.put("nation", UserCenterCommon.getInstance().getNation());
        saveUseMgsMap.put("password", UserCenterCommon.getInstance().getPassword());
        saveUseMgsMap.put("personName", UserCenterCommon.getInstance().getPersonName());
        saveUseMgsMap.put("personSex", UserCenterCommon.getInstance().getPersonSex());
        saveUseMgsMap.put("unionId", UserCenterCommon.getInstance().getUnionId());
        saveUseMgsMap.put("userAccount", UserCenterCommon.getInstance().getUserAccount());
        saveUseMgsMap.put("weight", UserCenterCommon.getInstance().getWeight());


        showProgressDialog(mActivity.getString(R.string.submiting));
        NoHttpUtils.httpPost(UserCenterConstant.URL_SAVE_REGISTER_INFO, saveUseMgsMap, mResponseListener, 0);
    }

    private NoHttpUtils.OnResponseListener mResponseListener = new NoHttpUtils.OnResponseListener() {
        @Override
        public void onSucceed(CommonClass commonClass, int what) {
            try {
                if ("0".equals(commonClass.getCode())) {
                    LoginResponseBean loginResponseBean = JSON.parseObject(commonClass.getData().toString(), LoginResponseBean.class);
                    if (loginResponseBean != null) {
                        LoginResponseBean.UserInfoBean userInfoBean = loginResponseBean.getUserInfo();

                        if (userInfoBean != null) {
                            sp.putValue(Constant.sp_Person_Name, userInfoBean.getPersonName());
                            sp.putValue(Constant.sp_Face_Url, userInfoBean.getFaceUrl());
                            sp.putValue(Constant.sp_User_Account, userInfoBean.getUserAccount());
                            sp.putValue(Constant.sp_User_Id, userInfoBean.getUserId());
                        }
                        if (loginResponseBean.getAuditName() != null && loginResponseBean.getAuditMobile() != null) {
                            String auditName = loginResponseBean.getAuditName();
                            String auditMobile = loginResponseBean.getAuditMobile();
                            sp.putValue(Constant.sp_Token, loginResponseBean.getToken());
                            Bundle bundle = new Bundle();
                            bundle.putString("auditName", auditName);
                            bundle.putString("auditMobile", auditMobile);
                            RegisterSuccessFragment registerSuccessFragment = new RegisterSuccessFragment();
                            registerSuccessFragment.setArguments(bundle);
                            ((RegisterCardActivity) mActivity).hideShowTitle(false);
                            pushFragment(registerSuccessFragment);

                            //发给成杰 用来结束他的登录界面
                            EventBus.getDefault().post("REGISTER_SUCCESS");
                        }

                        //                        startActivity(UserCenterConstant.PATH_MAIN, null, true);
                    }

                } else {
                    toast(commonClass.getMsg());
                }
            } catch (Exception e) {
                LogUtils.showLog(e.toString());
            }

        }

        @Override
        public void onFailed(String result, int what) {
            toast(result);
        }

        @Override
        public void onFinish(int what) {
            dismissProgressDialog();
        }
    };

    private boolean isTip = true;

    public void onEventMainThread(String string) {
        if ("SystemServiceActivity".equals(string)) {
            isSystemServiceActivity = true;
            UserCenterCommon.getInstance().setSystemServiceActivity(true);
        } else if ("RCInviteCodeFragment".equals(string)) {
            isRCInviteCodeFragment = true;
            UserCenterCommon.getInstance().setRCInviteCodeFragment(true);
        } else if ("RCRealNameAuthStep2Fragment".equals(string)) {
            isRCRealNameAuthStep2Fragment = true;
            UserCenterCommon.getInstance().setRCRealNameAuthStep2Fragment(true);
        } else if ("RCShootingHeadFragment".equals(string)) {
            isShootHead = true;
            UserCenterCommon.getInstance().setShootHead(true);
        } else if ("RCUserNamePasswordFragment".equals(string)) {
            isRCUserNamePasswordFragment = true;
            UserCenterCommon.getInstance().setRCUserNamePasswordFragment(true);
        } else if ("RCBindingFragment".equals(string)) {
            isRCBindingFragment = true;
            UserCenterCommon.getInstance().setRCBindingFragment(true);
        } else if ("FingerUnlockSettingsFragment".equals(string)) {
            if (sp.getBooleanValue(sp_Finger)) {
                isFingerUnlockSettingsFragment = true;
                UserCenterCommon.getInstance().setFingerUnlockSettingsFragment(true);
            } else {
                isFingerUnlockSettingsFragment = false;
                UserCenterCommon.getInstance().setFingerUnlockSettingsFragment(false);
            }
        } else if ("EnterEmployeeDataFragment".equals(string)) {
            isEnterEmployeeDataFragment = true;
            UserCenterCommon.getInstance().setEnterEmployeeDataFragment(true);
        } else if ("RegisterCardActivity".equals(string)) {
            //判断必选项是否完成
            if (isSystemServiceActivity && isRCInviteCodeFragment && isRCRealNameAuthStep2Fragment && isShootHead && isRCUserNamePasswordFragment && isRCBindingFragment) {
                getHeadIsOk();
            } else {
                //判断几项未完成
                if (isSystemServiceActivity) {
                    step -= 1;
                }
                if (isRCInviteCodeFragment) {
                    step -= 1;
                }
                if (isRCRealNameAuthStep2Fragment) {
                    step -= 1;
                }
                if (isShootHead) {
                    step -= 1;
                }
                if (isRCUserNamePasswordFragment) {
                    step -= 1;
                }
                if (isRCBindingFragment) {
                    step -= 1;
                }
                if (isFingerUnlockSettingsFragment) {
                    step -= 1;
                }
                if (isEnterEmployeeDataFragment) {
                    step -= 1;
                }
                if (step == 0) {
                    getHeadIsOk();//判断上传头像的是否上传好了
                } else {
                    toast(String.format(mActivity.getResources().getString(R.string.not_finished), step + ""));
                }
            }
        } else if ("back".equals(string)) {
            back();
        }
        if (isSystemServiceActivity && isRCInviteCodeFragment && isRCRealNameAuthStep2Fragment && isShootHead && isRCUserNamePasswordFragment && isRCBindingFragment && isTip) {
            isTip = false;
            PopItemView = View.inflate(getActivity(), R.layout.popup_new_register, null);
            mEasyPopupWindow = new EasyPopupWindow.Builder(getActivity())
                    .setView(PopItemView)
                    .setSize(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                    .setOutsideTouchHide(true)
                    .setBackgroundAlpha(0.6f)
                    .create();
            int loc[] = new int[2];
            mBtSubmit.getLocationOnScreen(loc);
            mEasyPopupWindow.getContentView().measure(0, 0);
            int width = mEasyPopupWindow.getContentView().getMeasuredWidth();
            mEasyPopupWindow.setAnimationStyle(R.style.popwin_anim_by_businessunit);
            DisplayMetrics metric = new DisplayMetrics();
            mActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
            int widthPixels = metric.widthPixels;     // 屏幕宽度
            mEasyPopupWindow.showAtLocation(mBtSubmit, Gravity.LEFT | Gravity.TOP, widthPixels / 2 - width / 2, loc[1] + mBtSubmit.getHeight() + 10);
        }
        //改变已经完成的模块的显示
        changeView();
    }


    public void back() {
        if (isSystemServiceActivity && isRCInviteCodeFragment && isRCRealNameAuthStep2Fragment && isShootHead && isRCUserNamePasswordFragment && isRCBindingFragment) {
            DialogTools.getInstance().showCustomDialogPromptNoTitleCancleListen(mActivity, mActivity.getResources().getString(R.string.is_submit),
                    false, new DialogTools.ConfirmListener() {
                        @Override
                        public void setConfirmListener(Dialog dialog, View view, String s) {
                            dialog.dismiss();
                            //判断头像是否上传成功
                            getHeadIsOk();
                        }
                    }, new DialogTools.DismissListener() {
                        @Override
                        public void setDismissListener(Dialog dialog, View view) {
                            UserCenterCommon.getInstance().setAllRegisterNull();
                            startActivity(UserCenterConstant.PATH_LOGIN_ACTIVITY, null, false);
                        }
                    }, mActivity.getResources().getString(R.string.finish_submit), mActivity.getResources().getString(R.string.quit_submit));
        } else if (isSystemServiceActivity || isRCInviteCodeFragment || isRCRealNameAuthStep2Fragment || isShootHead || isRCUserNamePasswordFragment || isRCBindingFragment) {
            DialogTools.getInstance().showCustomDialogPromptNoTitleCancleListen(mActivity, mActivity.getResources().getString(R.string.is_no_submit), false, new DialogTools.ConfirmListener() {
                @Override
                public void setConfirmListener(Dialog dialog, View view, String s) {
                    dialog.dismiss();
                }
            }, new DialogTools.DismissListener() {
                @Override
                public void setDismissListener(Dialog dialog, View view) {
                    dialog.dismiss();
                    UserCenterCommon.getInstance().setAllRegisterNull();
                    finishActivity();
                }
            }, mActivity.getResources().getString(R.string.go_on_submit), mActivity.getResources().getString(R.string.quit_submit));
        } else {
            finishActivity();
        }
    }


    @Override
    public void setTitle() {
        if (peekFragment() instanceof RegisterCardFragment) {
            mActivity.setTitle(R.string.register);
        }
    }

    @Override
    public void requestDatas() {

    }


    private void uploadPhoto(List<String> list) {

        NoHttpUtils.httpUploadFileRequest(Constant.URL_UPLOADS_AVATAR, list, new NoHttpUtils.OnFileUploadListener() {
            @Override
            public void onStart(int position) {

            }

            @Override
            public void onCancel(int position) {

            }

            @Override
            public void onProgress(int position, int progress) {

            }

            @Override
            public void onFinish(int position) {

            }

            @Override
            public void onError(int position, Exception exception) {

            }
        }, new NoHttpUtils.OnFileUploadResultListener() {
            @Override
            public void onSucceed(int what, FileUploadBean fileUploadBean) {
                if ("0".equals(fileUploadBean.getCode())) {
                    if (fileUploadBean.getData() != null && fileUploadBean.getData().size() > 0) {
                        List<FileUploadBean.DataBean> data = fileUploadBean.getData();
                        UserCenterCommon.getInstance().setFace(data.get(0).getPath());
                        Submit();
                    } else {
                        DialogTools.getInstance().showCustomWarningNoTitle(mActivity, mActivity.getResources().getString(R.string.head_up_failed), mActivity.getResources().getString(R.string.OK), false, new DialogTools.ConfirmListener() {
                            @Override
                            public void setConfirmListener(Dialog dialog, View view, String s) {
                                dialog.dismiss();
                            }
                        });
                    }

                } else {
                    DialogTools.getInstance().showCustomWarningNoTitle(mActivity, mActivity.getResources().getString(R.string.head_up_failed), mActivity.getResources().getString(R.string.OK), false, new DialogTools.ConfirmListener() {
                        @Override
                        public void setConfirmListener(Dialog dialog, View view, String s) {
                            dialog.dismiss();
                        }
                    });
                }


            }

            @Override
            public void onFailed(int what, FileUploadBean fileUploadBean) {
                DialogTools.getInstance().showCustomWarningNoTitle(mActivity, mActivity.getResources().getString(R.string.head_up_failed), mActivity.getResources().getString(R.string.OK), false, new DialogTools.ConfirmListener() {
                    @Override
                    public void setConfirmListener(Dialog dialog, View view, String s) {
                        dialog.dismiss();
                    }
                });
            }
        });
    }

    private void changeView() {
        if (isSystemServiceActivity) {//isServiceContract
            mRlRegisterCardServiceContract.setBackground(mActivity.getResources().getDrawable(R.drawable.unable_shape_409699e));
            mIvRegisterCardServiceContract.setImageResource(R.drawable.right_write);
            mTvRegisterCardServiceContract.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            mTvRegisterCardServiceContract.setText(mActivity.getResources().getString(R.string.agreed_web));
        }
        if (isRCInviteCodeFragment) {//isInviteCode
            mRlRegisterCardInviteCode.setBackground(mActivity.getResources().getDrawable(R.drawable.unable_shape_409699e));
            mIvRegisterCardInviteCode.setImageResource(R.drawable.right_write);
            mTvRegisterCardInviteCode.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            mTvRegisterCardInviteCode.setText(mActivity.getResources().getString(R.string.check_success));
        }
        //上面两个完成后其他颜色变亮
        if (isSystemServiceActivity && isRCInviteCodeFragment) {
            mRlRealNameAuth.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
            mIvRealNameAuth.setImageResource(R.drawable.icon_idcard2);
            mTvRealNameAuth.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));
            mRlShootingHead.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
            mIvShootingHead.setImageResource(R.drawable.icon_head2);
            mTvShootingHead.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));
            mRlUserNamePassword.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
            mIvUserNamePassword.setImageResource(R.drawable.icon_password2);
            mTvUserNamePassword.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));
            mRlBinding.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
            mIvBinding.setImageResource(R.drawable.icon_bind2);
            mTvBinding.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));
            mRlFingerprintUnlockSettings.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
            mIvFingerprintUnlockSettings.setImageResource(R.drawable.icon_pact2);
            mTvFingerprintUnlockSettings.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));
            mRlInputData.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
            mIvInputData.setImageResource(R.drawable.icon_invite_id2);
            mTvInputData.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));


            if (isRCRealNameAuthStep2Fragment) {//isRealNameAuth
                mRlRealNameAuth.setBackground(mActivity.getResources().getDrawable(R.drawable.unable_shape_409699e));
                mTvRealNameAuth.setText(mActivity.getResources().getString(R.string.pass_real_name));
                mTvRealNameAuth.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                mIvRealNameAuth.setImageResource(R.drawable.right_write);
            }
            if (isShootHead) {//isShootingHead
                mIvHead.setVisibility(View.VISIBLE);
                BaseApplication.getApplicationInstance().displayRoundImgPixel("file://" + UserCenterCommon.getInstance().getAbsolutePath(), mIvHead, ConvertUtils.dip2px(mActivity, 3));
                BaseApplication.getApplicationInstance().clearMomeryCache("file://" + UserCenterCommon.getInstance().getAbsolutePath());
            }
            if (isRCUserNamePasswordFragment) {//isNamePassword
                mRlUserNamePassword.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_c1_shape));
                mIvUserNamePassword.setImageResource(R.drawable.right_write);
                mTvUserNamePassword.setText(mActivity.getResources().getString(R.string.set_name_password));
                mTvUserNamePassword.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                mTvUserName.setVisibility(View.VISIBLE);
                mTvUserName.setText(UserCenterCommon.getInstance().getUserAccount());
            }
            if (isRCBindingFragment) {//isBinding
                mRlBinding.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_c13_shape));
                mIvBinding.setImageResource(R.drawable.right_write);
                mTvBinding.setText(mActivity.getResources().getString(R.string.binded));
                mTvBinding.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                mTvBindPhone.setVisibility(View.VISIBLE);
                mTvBindEmail.setVisibility(View.VISIBLE);
                String mobile = UserCenterCommon.getInstance().getMobile();
                String maskNumber = mobile.substring(0, 3) + "****" + mobile.substring(7, mobile.length());
                mTvBindPhone.setText(maskNumber);
                String email = UserCenterCommon.getInstance().getEmail();
                String emailFront = email.substring(0, email.indexOf("@"));
                if (emailFront.length() > 4) {
                    emailFront = email.substring(0, 4);
                }
                String emailEnd = email.substring(email.lastIndexOf(".") + 1, email.length());
                if (emailEnd.length() > 3) {
                    emailEnd = emailEnd.substring(0, 3);
                }
                mTvBindEmail.setText(emailFront + "****" + emailEnd);
            }
            if (isFingerUnlockSettingsFragment) {//isFingerprintUnlockSettings
                mRlFingerprintUnlockSettings.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_c12_shape));
                mIvFingerprintUnlockSettings.setImageResource(R.drawable.right_write);
                mTvFingerprintUnlockSettings.setText(mActivity.getResources().getString(R.string.finger_start));
                mTvFingerprintUnlockSettings.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
            } else {
                mRlFingerprintUnlockSettings.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_fff_shape));
                mIvFingerprintUnlockSettings.setImageResource(R.drawable.icon_pact2);
                mTvFingerprintUnlockSettings.setTextColor(mActivity.getResources().getColor(R.color.usercenter_e6585d62));
            }
            if (isEnterEmployeeDataFragment) {//isInputData
                mRlInputData.setBackground(mActivity.getResources().getDrawable(R.drawable.common_card_background_c1_shape));
                mIvInputData.setImageResource(R.drawable.right_write);
                mTvInputData.setText(mActivity.getString(R.string.entryed));
                mTvInputData.setTextColor(mActivity.getResources().getColor(R.color.common_color_c3_ffffff));
                mTvInputDatas.setVisibility(View.VISIBLE);
                BigDecimal height = UserCenterCommon.getInstance().getHeight();
                BigDecimal weight = UserCenterCommon.getInstance().getWeight();
                String eyesight = UserCenterCommon.getInstance().getEyesight();
                boolean isWeek = UserCenterCommon.getInstance().getIsWeek();
                inputDatas = height + " " + weight + " ";
                if (eyesight.contains("1")) {
                    inputDatas += mActivity.getResources().getString(R.string.myopia) + " ";
                }
                if (eyesight.contains("2")) {
                    inputDatas += mActivity.getResources().getString(R.string.color_blind) + " ";
                }
                if (eyesight.contains("3")) {
                    inputDatas += mActivity.getResources().getString(R.string.color_week) + " ";
                }
                if (eyesight.contains("4")) {
                    inputDatas += mActivity.getResources().getString(R.string.presbyopia) + " ";
                }
                if (isWeek) {
                    inputDatas += mActivity.getResources().getString(R.string.canji);
                }

                mTvInputDatas.setText(inputDatas);
            }

        }


    }

    private String inputDatas = "";

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


}
